{extend name="$BASE_LIST" /}
{block name="body"}
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/dateRange.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/monthPicker.css"/>

<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">{$page_nav}</span></div>
    <ul class="tab_navs" id="js_tab_navs">
        <li class="{if condition='$status eq 0'}current{/if}"><a class="pjax" href="{:getUrl('index','status=0')}">未审核</a></li>
        <li class="{if condition='$status eq 1'}current{/if}"><a class="pjax" href="{:getUrl('index','status=1')}">已审核</a></li>
        <li class="{if condition='$status eq -1'}current{/if}"><a class="pjax" href="{:getUrl('index','status=-1')}">不通过</a></li>
    </ul>
    <div id="js_main_header" class="ui-form main_header">
        

        <div class="left margin-right-5">
            <input style="width:200px" class="form-control" id="month_picker" size="20"/>
        </div>
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="js_keyword" placeholder="请输入用户名\手机号" value="" class="frm_input" />
        </span>
<!--        <span class="right">-->
<!--            <button type="button" id="js_expBtn" class="btn btn-primary"><i class="icon wb-download"></i> 导出</button>-->
<!--        </span>-->

    </div>
<!--    {if condition="$status==0"}-->
<!--        <div class="" style="padding-bottom: 3px">-->
<!--            <span>全选:</span><input id="selectAll" style="width:30px;height: 18px;" class="form-control" type="checkbox"  />-->
<!--            <span></span>-->
<!--            <button type="button" onclick="doCheckAll()" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>一键通过</button>-->
<!--        </div>-->
<!--    {/if}-->
    <table id="grid-table">
        <thead frozen="true">
<!--            {if condition="$status==0"}-->
<!--                <th data-options="field:'id',width:50,align:'center',formatter: formatSelect">选择</th>-->
<!--            {/if}-->
            <th data-options="field:'user_id',width:100,align:'center'">用户id</th>
            <th data-options="field:'phone',width:100,align:'center'">手机号</th>
            <th data-options="field:'username',width:100,align:'center'">用户名称</th>
            <th data-options="field:'ref_no',width:200,align:'center'">提现单号</th>
            <th data-options="field:'amount',width:100, align:'center'">提现数量</th>
            <th data-options="field:'balance_name',width:120, align:'center'">提现类型</th>
            <th data-options="field:'rate',width:100, align:'center'">提现手续费</th>
            <th data-options="field:'gx_amount',width:100, align:'center'">贡献值</th>
             <th data-options="field:'withdrawal_address',width:260, align:'center'">提现地址信息</th>
        </thead>
        <thead>
            <th data-options="field:'status',width:100, align:'center',formatter:formatStatus">审核状态</th>
            <th data-options="field:'add_time',width:140,align:'center'">创建时间</th>
            <th data-options="field:'_oper',width:250,halign:'center',formatter: formatOper">操作</th>
        </thead>
    </table>
</div>

{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/monthPicker/dateRange.js"></script>
<script type="text/javascript" src="__STATIC__/monthPicker/monthPicker.js"></script>
<script type="text/javascript">
    var myDate = new Date();
    var month = parseInt(myDate.getMonth()) + 1;
    var toDay = myDate.getFullYear() + '-' + month + '-' + myDate.getDate();
    var dateRange = new pickerDateRange('month_picker', {
        startDate: '2000-01-01',
        endDate: toDay,
        defaultText: ' 至 ',
        theme: 'ta'
    });
    var status = '{$status}';
    $('body').on('click','#selectAll',function(){
        var check = $(this).prop('checked');
        $(".vehicle").prop("checked",check); 
    })
    function formatOper(value, row, index) {
        console.log(row)
        if (row.status == 0){
            var html = '<span class="grid-operation">';
            html += '<button type="button" onclick="doCheck(' + row['id'] + ',1)" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>通过</button>';
            // if(row.coin_type!=3){
                html += '<button type="button" onclick="doCheck(' + row['id'] + ',-1)" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>不通过</button>';
            // }
            html += '</span>';
        }
        return html;
    }
    function formatSelect(value, row, index){
        html = '<input class="vehicle" type="checkbox" name="vehicle" value="'+row['id']+'"  />';
        return html;
    }
    function formatType(value){
        switch (value){
            case 1 :
                var text = '<span style="">ETH</span>';
                break;
            case 2 :
                var text = '<span style="">USDT</span>';
                break;
            case 3 :
                var text = '<span style="">SPD</span>';
                break;
            case 4 :
                var text = '<span style="">USDP</span>';
                break;
            default:

        }
        return text;
    }
    //状态
    function formatStatus(value,row,index){
        switch (value){
            case 1 :
                var text = '<span style="color:red">已审核</span>';
                break;
            case -1 :
                var text = '<span style="color:red">未通过</span>';
                break;
            case 0 :
                var text = '<span style="color:red">未通过</span>';
                break;
            default:
                var text = '';

        }
        return text;
    }
    //审核
    function doCheck(id,status){
        var title = '审核通过?';
        if(status == -1)
            title = '审核不通过?';
        confirm(title, function () {
            var url = getURL('doCheck');
            $.getJSON(url, {id: id,status:status}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }
    //审核所选
    function doCheckAll(){
        var str = "";
        $(".vehicle").each(function (index, item) {
            if($(this).prop('checked')){
                str += $(this).val() + ",";
            }
        });
        console.log(str);
        var title = '确定一键审核通过?';
        confirm(title, function () {
            var url = getURL('doCheckMore');
            $.getJSON(url, {id: str}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }
    
    
    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList','status='+status),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20,
            showFooter:true,
            onLoadSuccess: function(data){
                $('#grid-table').datagrid('reloadFooter', [
                    {
                        user_id: '统计',
                        amount: data.count_total,
                        status:'100'
                    }
                ]);
            }
        });
        //设置分页控件 
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10 
            pageList: [20, 30, 50]
        });
    });

    $("#js_search").click(function () {
        reload();
    });
    function reload() {
        var keyword = $("#js_keyword").val();
        var month_picker = $("#month_picker").val();
        var arr = month_picker.split(" 至 ");
        var startDate = arr[0];
        var endDate = arr[1];
        $('#grid-table').datagrid('reload', {keyword: keyword,startDate: startDate,endDate: endDate});
    }
    $("#type").change(function () {
        reload();
    });

    $("#js_expBtn").click(function () {
        var keyword = $("#js_keyword").val();
        var month_picker = $("#month_picker").val();
        var arr = month_picker.split(" 至 ");
        var startDate = arr[0];
        var endDate = arr[1];
        location.href = getURL('export')+'?keyword='+keyword+"&startDate="+startDate+"&endDate="+endDate+"&status="+status;
    });
</script>
{/block}